//
//  main.cpp
//  HelloLinux
//
//  Created by huge on 2021/6/24.
//  Copyright © 2021 huge. All rights reserved.
//

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>    // std::equal

using namespace std;


bool mypredicate (int i, int j) {
    return (i==j);
}

int equal_main () {
    vector<string> myvector = {"20","40","60","80","100"};               //   myints: 20 40 60 80 100
//    std::vector<string>myvector (myints,myints+5);     // myvector: 20 40 60 80 100
    
    // using default comparison:
    if ( std::equal (myvector.begin(), myvector.end(), myints) )
        std::cout << "The contents of both sequences are equal.\n";
    else
        std::cout << "The contents of both sequences differ.\n";
    
//    myvector[3]=81;                                 // myvector: 20 40 60 81 100
    
    // using predicate comparison:
    if ( std::equal (myvector.begin(), myvector.end(), myints, mypredicate) )
        std::cout << "The contents of both sequences are equal.\n";
    else
        std::cout << "The contents of both sequences differ.\n";
    
    return 0;
}

class Solution {
    
public:
    string longestCommonPrefix(vector<string>const & strs) {
        if (!strs.size()) {
            return "";
        }
        string prefix = strs[0];
        int count = strs.size();
        for (int i = 1; i < count; ++i) {
            prefix = longestCommonPrefix(prefix, strs[i]);
            if (!prefix.size()) {
                break;
            }
        }
        return prefix;
    }
    
    string longestCommonPrefix(const string& str1, const string& str2) {
        int length = min(str1.size(), str2.size());
        int index = 0;
        while (index < length && str1[index] == str2[index]) {
            ++index;
        }
        return str1.substr(0, index);
    }
};



int main(int argc, const char * argv[]) {
    
    
    std::cout<<"hello world!"<<"test"<<std::endl;
    
    Solution *pSol = new Solution();
    
//    vector<string> strs = {"abca","abc","abca","abc","abcc"};
//    string longestPrefix = pSol->longestCommonPrefix(strs);
//    cout << "longest: " << longestPrefix << endl;
    
    equal_main();
    return 0;
}
